<script lang="ts">
	import { Command } from "cmdk-sv";
	import { register } from "@tauri-apps/plugin-global-shortcut";
	import { getCurrentWindow } from "@tauri-apps/api/window";

	import "../styles/globals.postcss";
	import "../styles/raycast.postcss";
	import { onMount } from "svelte";

	let loading = false;

	onMount(async () => {
		await register("CommandOrControl+Alt+D", async () => {
			console.log("Shortcut triggered");
			const appWindow = getCurrentWindow();
			const isVisible = await appWindow.isVisible();
			appWindow.setVisibleOnAllWorkspaces(!isVisible);
		});
	});
</script>

<main class="raycast">
	<Command.Root>
		<Command.Input autofocus placeholder="Search for apps and commands..." />
		<hr data-cmdk-raycast-loader="" />
		<Command.List>
			{#if loading}
				<Command.Loading>Loading...</Command.Loading>
			{/if}

			<Command.Empty>No results found.</Command.Empty>

			<Command.Group heading="Fruits">
				<Command.Item>Apple</Command.Item>
				<Command.Item>Orange</Command.Item>
				<Command.Separator />
				<Command.Item>Pear</Command.Item>
				<Command.Item>Blueberry</Command.Item>
			</Command.Group>

			<Command.Item>Fish</Command.Item>
		</Command.List>
	</Command.Root>
</main>
